package com.financial.business.management.service.impl;

import com.financial.business.management.constants.FinancialPlatfromConfigEnumConstants;
import com.financial.business.management.dao.FinancialPayConfigDao;
import com.financial.business.management.domain.FinancialPayConfigDO;
import com.financial.business.management.service.FinancialPayConfigService;
import com.financial.business.management.utils.apiresult.ApiResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class FinancialPayConfigServiceImpl implements FinancialPayConfigService {
	@Autowired
	private FinancialPayConfigDao financialPayConfigDao;
	
	@Override
	public FinancialPayConfigDO get(Integer id){

		return financialPayConfigDao.get(id);
	}
	
	@Override
	public List<FinancialPayConfigDO> list(Map<String, Object> map){
		return financialPayConfigDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return financialPayConfigDao.count(map);
	}
	
	@Override
	public int save(FinancialPayConfigDO financialPayConfig){
		return financialPayConfigDao.save(financialPayConfig);
	}
	
	@Override
	public int update(FinancialPayConfigDO financialPayConfig){
		return financialPayConfigDao.update(financialPayConfig);
	}
	
	@Override
	public int remove(Integer id){
		return financialPayConfigDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return financialPayConfigDao.batchRemove(ids);
	}

	@Override
	public ApiResult createPayConfig(String payType) {
		if(StringUtils.isEmpty(payType)){
			return ApiResult.paramIsNull();
		}
        FinancialPayConfigDO financialPayConfigDO = new FinancialPayConfigDO();
        financialPayConfigDO.setGmtCreate(new Date());
        financialPayConfigDO.setGmtModified(new Date());
        financialPayConfigDO.setIsDelete(FinancialPlatfromConfigEnumConstants.ENUM_ISDELETE_UNDEL);
        financialPayConfigDO.setPayType(payType);
        int saveSum = financialPayConfigDao.save(financialPayConfigDO);
        if(saveSum>0){
            return ApiResult.success();
        }
        return ApiResult.failure();
	}

	@Override
	public int getChannelsId(String payType) {
        Map<String, Object> paytypeMap = new HashMap<>();
        paytypeMap.put("pay_type",payType);
        paytypeMap.put("is_delete",FinancialPlatfromConfigEnumConstants.ENUM_ISDELETE_UNDEL);
        List<FinancialPayConfigDO> list = financialPayConfigDao.list(paytypeMap);
        FinancialPayConfigDO financialPayConfigDO = list != null && list.size() > 0 ? list.get(0) : null;
        return financialPayConfigDO.getId();
	}

}
